<template>
    <div>
        <el-row>
        <el-col :span="16"  v-for="(item,o) in GreenLand" :key="o" :offset="4"  >
            <el-card :body-style="{ padding: '0px' }">
            <div class="images" >
            <el-image :src="photo.photoUrl"
                :lazy="true" fit="fill " v-for="(photo,photoIndex) in item.greenLandPhotos" :key="photoIndex">
                    <div slot="error" >
                        <div class="image-slot">
                            <i class="el-icon-picture-outline"></i>
                            加载失败
                        </div>
                    </div>
            </el-image>
            </div>
            <div style="padding: 14px;">
                <span>{{item.name}}</span>
                <div class="bottom clearfix">
                <time class="time">{{ item.date }}</time>
                <el-button type="text" class="button" icon="el-icon-edit" style="margin:0 20px" @click="showDetails(item)">编辑</el-button>
                <el-button type="text" class="button"  icon="el-icon-delete" style="margin:0 20px;color: red;" @click="del(item.id)">删除</el-button>
                <el-button type="text" class="button"  icon="el-icon-warning" style="margin:0 20px;color:rgb(238, 189, 63);" @click="setWaring(item)">设置警报</el-button>
            </div>
            </div>
            </el-card>
        </el-col>
        </el-row>
        <Details ref="details" :greenLand="toDetails" @OK="findAll"></Details>
        <setting-waring ref="settingWaring"></setting-waring>
    </div>
</template>

<script>
import { AxiosGet } from '../../axios'
import Details from './Details.vue'
import settingWaring from './settingWaring.vue';
export default {
    name: 'GreenLandIndex',

    data() {
        return {
             currentDate: new Date(),
             GreenLand:[],
             search:'',
             toDetails:[]
        };
    },
    components:{Details,settingWaring},
    mounted() {
        this.findAll()
    },

    methods: {
        setWaring(item){
            this.$refs.settingWaring.greenLand = item
            this.$refs.settingWaring.show()
            
        },
        findAll(){
            AxiosGet('greenLand/findAll').then(sucess=>{
                this.GreenLand=sucess.data
                this.GreenLand.sort((a,b)=>{
                    // 时间倒序排序
                    return a.date<b.date ? 1 : -1
                })
            })
        },
        showDetails(greenLand){
             this.$refs.details.greenLand=greenLand
            this.$refs.details.show()
        },
         del(id) {
            this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                AxiosGet('greenLand/del/'+id).then(sucess=>{
                    console.log(sucess);
                    this.$message({
                        type: 'success',
                        message: sucess.data
                    });
                })
            console.log(id);
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消删除'
            });          
            });
        }
       
    },
};
</script>

<style scoped>
.el-col{
    margin-bottom: 20px;
}
.el-image{
    width: 50%;
}
.image-slot,el-icon-picture-outline{
    background-color: rgb(243, 249, 218);
    width: 200px;
    height: 200px;
    display: flex;
    flex-direction: column;
    color: rgb(117, 117, 117) ;
    align-items: center;
    justify-content: center;
}
 .time {
    font-size: 13px;
    color: rgb(153, 153, 153);
  }
  .images{
      display: flex;
      flex-direction: row;
      justify-items: center;
      justify-content: center;
      align-content: center;
  }
  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    padding: 0;
    float: right;
  }

  .el-image {
    height: 200px;
    display: block;
  }
  .clearfix:before,
  .clearfix:after {
      display: table;
      content: "";
  }
  
  .clearfix:after {
      clear: both
  }
</style>